package org.example.member.controller.front;

import org.example.core.to.LoginMemberTo;
import org.example.core.utils.R;
import org.example.member.service.MemberService;
import org.example.member.vo.front.MemberInfoVo;
import org.example.member.vo.front.MemberUpdateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 小杰_cc
 * @version 1.0
 */
@RestController
@RequestMapping("/ums/front/member")
public class MemberFrontController {

    @Autowired
    private MemberService memberService;

    /**
     * 登录
     */
    @PostMapping("/login")
    public R<?> login(@RequestBody String phone){
        LoginMemberTo vo = memberService.login(phone);
        return R.ok(vo);
    }

    /**
     * 获取对应用户基本信息
     */
    @GetMapping("/info")
    public R<MemberInfoVo> memberInfo(){
        MemberInfoVo vo = memberService.queryMemberInfo();
        return R.ok(vo);
    }

    /**
     * 修改用户头像
     */
    @PutMapping("/header")
    public R<?> updateHeader(@RequestBody String header){
        return memberService.updateHeader(header)>0? R.ok():R.error();
    }

    /**
     * 修改会员基本信息
     * @param memberUpdateVo
     * @return
     */
    @PutMapping("/update")
    public R<?> updateMemberInfo(@Validated @RequestBody MemberUpdateVo memberUpdateVo){
        return memberService.updateMemberInfo(memberUpdateVo)>0? R.ok():R.error();
    }
}
